package com.tianbo.elfii.client.common;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


import com.base.Download.UPDATE_RESULT;
import com.tianbo.elfii.client.common.ElfiiCommonUtil.FeedBackType;
import com.tianbo.elfii.client.common.wlanmanagement.BaseDialogPane;


public class ManualUpdatePane extends BaseDialogPane {

	public Container contentPane = null; 
	public ManualUpdateDialog dialog = null; 

	public ManualUpdatePane() {
		super();
		// TODO Auto-generated constructor stub
		
		this.screenshot();
		
		initManulUpdateDialog();
		
		dialog.setOpaque(false);
	}
	
	public void initManulUpdateDialog(){
		dialog = new ManualUpdateDialog();
		dialog.setBounds(240, 248, 545, 272);
		dialog.init();
		dialog.confirmBtn.addActionListener(new ConfirmBtnListener());
		dialog.cancelBtn.addActionListener(new CancelBtnListener());
		this.add(dialog);
	}

	public class CancelBtnListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			ElfiiCommonUtil.playFeedbackAudio(FeedBackType.CLICK);
			mainFrame.setContentPane(contentPane);
		}
	}
	
	
	public class ConfirmBtnListener implements ActionListener {

		int ret = -1;
		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			ElfiiCommonUtil.playFeedbackAudio(FeedBackType.CLICK);
			if(ret == UPDATE_RESULT.OK){
				mainFrame.setContentPane(contentPane);
				return;
			}
			
			dialog.tipStr = "";
			
			dialog.repaint();
			
			dialog.confirmBtn.setEnabled(false);
			dialog.cancelBtn.setEnabled(false);
			
            ret = com.base.Download.upFile();
            
            switch(ret){
            case UPDATE_RESULT.NO_USB:
            	dialog.tipStr = "请插入更新U盘!";
            	break;
            case UPDATE_RESULT.NO_FILE:
            	dialog.tipStr = "更新包不存在!";
            	break;
            case UPDATE_RESULT.OK:
            	dialog.tipStr = "软件已更新至版本V"+ElfiiCommonConfigUtil.getSwVersion();
            	break;
            default:
            	dialog.tipStr = "更新失败!";
            	break;
            }
            
            dialog.repaint();
			dialog.confirmBtn.setEnabled(true);
			dialog.cancelBtn.setEnabled(true);

		}
	}


}
